package com.wnhoo.smartfishtank.contants.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import com.wnhoo.smartfishtank.R;


public class ImageAdapter extends BaseAdapter {
    public final static String timing_color1 = "33cc33";
    public final static String timing_color2 = "66cc66";
    public final static String timing_color3 = "cccc66";
    public final static String timing_color4 = "4c4ccc";
    public final static String timing_color5 = "4ccccc";
    public final static String timing_color6 = "7fcc7f";
    public final static String timing_color7 = "ffff00";
    public final static String timing_color8 = "ff0000";
    public final static String timing_color9 = "29aae1";
    public final static String timing_color10 = "92278e";
    public final static String timing_color11 = "39b44a";
    public final static String timing_color12 = "f05a24";
    public final static String timing_color13 = "00ff00";
    public final static String timing_color14 = "ec1e79";
    public final static String timing_color15 = "ff7bab";
    public final static String timing_color16 = "1b1464";

    private static final String TAG = "ImageAdapter";
    private static String[] color = new String[]{timing_color1,timing_color2,timing_color3,timing_color4,timing_color5
            ,timing_color6,timing_color7,timing_color8,timing_color9,timing_color10,
            timing_color11,timing_color12,timing_color13,timing_color14,timing_color15,timing_color16};;
    private Context mContext;
    private ImageView imageview;
    private int clickTemp = -1;

    public static String[] getColor() {
        return color;
    }

    public ImageAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return color.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    public void setSeclection(int position) {
        clickTemp = position;
        if (clickTemp == -1) {
            clickTemp = 1;
        }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        imageview = null;
        if (convertView == null) {
            imageview = new ImageView(mContext);
            imageview.setLayoutParams(new GridView.LayoutParams((int) mContext.getResources().getDimension(R.dimen.digswitch_horizontal_height),
                    (int) mContext.getResources().getDimension(R.dimen.digswitch_horizontal_height)));
//            imageview.setScaleType(ImageView.ScaleType.FIT_END);
            imageview.setPadding(15, 15, 15, 15);

//            imageview.setBackgroundResource(R.drawable.solid4);
        } else {
            imageview = (ImageView) convertView;
        }
//        if (clickTemp == position) {
//            imageview.setBackgroundResource(R.drawable.solid3);
//        }else{
//            imageview.setLayoutParams(new GridView.LayoutParams(150, 150));
//            imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
//            imageview.setPadding(15,15,15,15);
//            imageview.setBackgroundResource(R.drawable.solid4);
//        }
//        imageview.setImageResource(color[position]);
        imageview.setBackgroundColor(Color.parseColor("#"+color[position]));
        return imageview;
    }

}
